Skip to content

[serde_multipart] new crate: multipart codec for serde #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: gh/mariusae/34/base
Choose a base branch
from

Conversation

mariusae
Copy link
Member

@mariusae mariusae commented Aug 12, 2025

Stack from ghstack (oldest at bottom):

Serde codec for multipart messages.

//! Using [serialize] / [deserialize], fields typed [Part] are extracted
//! from the main payload and appended to a list of parts. Each part is backed by
//! [bytes::Bytes] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [Message] (body + parts). Your transport sends
//! and receives [Message]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [Part]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [serialize] / [deserialize]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [part::PartSerializer] and [part::PartDeserializer]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: D80108937

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/)

[ghstack-poisoned]
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 12, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D80108937

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D80108937

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D80108937

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D80108937

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D80108937

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D80108937

shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303723935
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303723935
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.

Differential Revision: [D80108937](https://our.internmc.facebook.com/intern/diff/D80108937/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D80108937

shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
shayne-fletcher pushed a commit to shayne-fletcher/monarch-1 that referenced this pull request Aug 18, 2025
Summary:

Serde codec for multipart messages.

//! Using [`serialize`] / [`deserialize`], fields typed [`Part`] are extracted
//! from the main payload and appended to a list of `parts`. Each part is backed by
//! [`bytes::Bytes`] for cheap, zero-copy sharing.
//!
//! On decode, the body and its parts are reassembled into the original value
//! without copying.
//!
//! The on-the-wire form is a [`Message`] (body + parts). Your transport sends
//! and receives [`Message`]s; the codec reconstructs the value, enabling
//! efficient network I/O without compacting data into a single buffer.
//!
//! Implementation note: this crate uses Rust's min_specialization feature to enable
//! the use of [`Part`]s with any Serde serializer or deserializer. This feature
//! is fairly restrictive, and thus the API offered by [`serialize`] / [`deserialize`]
//! is not customizable. If customization is needed, you need to add specialization
//! implementations for these codecs. See [`part::PartSerializer`] and [`part::PartDeserializer`]
//! for details.

This will be the foundation for doing zero-copy I/O through our networking stack. With serde_multipart, we can avoid copying byte buffers, and delegate their efficient transmission to the network layer.

The representation -- a multipart message comprising a body and zero or more contiguous byte buffers -- lends itself to other optimizations as well. For example, we could perform transparent RDMA for large parts, and even control the allocation of the received bytes (through the Bytes data type).

The implementation relies on Rust's "min_specialization" feature, which provides a limited form of specialization. This is what allows us to override the serializer for "serde_multipart::Part" when using our multipart-aware encoder. This was quite finnicky to get to work right (the feature accepts only a limited subset of known-to-be-sound specializations), but appears to work well, at the expense of being slightly less generic than we might otherwise have managed.
ghstack-source-id: 303813996
exported-using-ghexport

Reviewed By: vidhyav, shayne-fletcher

Differential Revision: D80108937
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot. fb-exported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants